<template>
  <div class="box">
    <div>
      <el-input 
          class="input"
          v-model="caption" 
          size="mini" 
          placeholder="添加图片信息"
          clearable
          @change="postImg" />
      <!-- 选中上传的图片 -->
      <el-upload
            action="/test"
            list-type="picture-card"
            :on-preview="imgPreview"
            :on-remove="imgRemove">
        <i class="el-icon-plus"></i>
      </el-upload>
      <!-- 显示上传的图片 -->
      <el-dialog :visible.sync="dialogVisible">
        <img :src="imgUrl" alt="">
      </el-dialog>
    </div>
  </div>
</template>

<script>
// import axios from 'axios'

export default {
  name: 'ImgPage',
  data() {
    return {
      caption: '11',
      dialogVisible: false,
      imgUrl: '',
    }
  },
  methods: {
    postImg() {
      // axios.post({
      //   url: 'http://localhost:8001/data/imgs.json',
      //   data: {
      //     caption: this.caption,
      //     // imgUrl: this.imgUrl
      //   },
      //   header: {
      //     'Content-Type': 'application/json'
      //   }
      // })
    },
    imgPreview(file) {
      this.imgUrl = file.url
      console.log(this.imgUrl);
      this.dialogVisible = true
    },
    imgRemove(file, fileList) {
      console.log(file, fileList);
    }
  },
  mounted() {
    this.postImg();
  }
}
</script>

<style scoped>
 .input {
   width: 15%;
 }
</style>